package com.yang.controller.admin;


import com.yang.bean.common.BaseRespVo;
import com.yang.bean.common.CommonData;
import com.yang.bean.dhr.MarketAdminUpdateVo;
import com.yang.bean.dhr.MarketAdminVo;
import com.yang.bean.dhr.MarketAdminVo1;
import com.yang.service.admin.AdminAdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author stone
 * @date 2022/09/06 11:41
 */

@RestController
@RequestMapping("admin/admin")
public class AdminAdminController {
    @Autowired
    AdminAdminService adminAdminService;

    @RequestMapping("list")
    public BaseRespVo queryAllAdmin(Integer page, Integer limit, String sort, String order, String username) {
        CommonData<MarketAdminVo> commonData = adminAdminService.queryAllAdmin(page,limit,sort,order,username);
        BaseRespVo<CommonData<MarketAdminVo>> baseRespVo = new BaseRespVo<CommonData<MarketAdminVo>>();
        baseRespVo.setErrno(0);
        baseRespVo.setData(commonData);
        baseRespVo.setErrmsg("成功");
        return baseRespVo;
    }

    @RequestMapping("create")
    public BaseRespVo<MarketAdminVo1> createAdmin(@RequestBody MarketAdminVo1 marketAdminVo1) {
        marketAdminVo1 = adminAdminService.createAdmin(marketAdminVo1);
        BaseRespVo<MarketAdminVo1> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setData(marketAdminVo1);
        return baseRespVo;
    }

    @RequestMapping("update")
    public BaseRespVo<MarketAdminUpdateVo> updateAdmin(@RequestBody MarketAdminVo1 marketAdminVo1) {
        MarketAdminUpdateVo updateVo = adminAdminService.updateAdmin(marketAdminVo1);
        BaseRespVo<MarketAdminUpdateVo> baseRespVo = new BaseRespVo<>();
        baseRespVo.setErrno(0);
        baseRespVo.setErrmsg("成功");
        baseRespVo.setData(updateVo);
        return baseRespVo;
    }

    @RequestMapping("delete")
    public BaseRespVo deleteAdmin(@RequestBody MarketAdminVo1 marketAdminVo1) {
        adminAdminService.deleteAdmin(marketAdminVo1);
        return BaseRespVo.ok();
    }
}
